<?php 
	require_once(dirname(__FILE__)."/../config/config.php"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="60" />
<title>定单详细信息</title>
<style type="text/css">
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
a.current {text-decoration: underline;font-weight: bold;}
</style> 
</head>
<body>
<?php  
if($_SESSION['admin_name']=="")
{

	echo "<script>location.href='admin_login.php';</script>";
}
?>
<h1 align="center">定单详细信息</h1>
<?php 
 // 1 定义分页变量
 	$page = isset($_GET["page"])?$_GET["page"]:1;	//当前页号
	$pageSize = 20;				//页面大小	
	$maxRows;					// 最大数据条
	$maxPages;					// 最大页数
 // 2获取最大数据条数
 	$sql_2 = "select count(*) from zy_order";
	$res_2 = mysql_query($sql_2);
	$maxRows = mysql_result($res_2,0,0);//定位获取总条数
 // 3计算出共计最大页数
 	$maxPages=ceil($maxRows/$pageSize);
	$init = 1;
	$max = $maxPages;
	$pagelen = 5;
	// $pagelen = ($pagelen%2)?$pagelen:$pagelen+1;
	$pageoffset = 2;
	if($maxPages>$pagelen){
		if($page<=$pageoffset)
		{
			$init=1;
			$max = $pagelen;
		}else{
			if($page+$pageoffset>=$maxPages+1){
				$init = $maxPages-$pagelen+1;
			}else{
				$init = $page-$pageoffset;
				$max=$page+$pageoffset+1;
			}	
		}
	}
 // 4 效验当前页数
 	if($page>$maxPages){
		$page=$maxPages;
	}
	if($page<1){
		$page=1;
	}
 //5 拼装分页sql语句片段
	$limit = " limit ".(($page-1)*$pageSize).",{$pageSize}"; 
?>
<form id="form1" name="form1" method="post" action="">
  <table width="900" height="25" align="center" border="1">
    <tr>
	  <td width="58" height="25">订单号</td>
	  <td width="58" height="25">店铺名称</td>
      <td width="58" height="25">订单人</td>
	  <td width="58" height="25">收货地址</td>
	   <td width="58" height="25">手机号码</td>
	   <td width="58" height="25">备用号码</td>
      <td width="58" height="25">备注</td>
	  <td width="58" height="25">下单时间</td>
	  <td width="99" height="25">定单总价格</td>
    </tr>
	 <?php	
	 $sql=mysql_query("select * from zy_order order by ord_id desc {$limit}");
	// echo "select * from zy_order order by ord_id desc {$limit}";
  while($zy_order=mysql_fetch_array($sql)){
  ?>
    <?php  
      if($zy_order['user_id']!=0){
	    if($zy_order['add_id']!=0){
	$sql3="select * from zy_address where add_id ='".$zy_order['add_id']."'";
	}else{
		$sql3="select * from zy_address where create_time ='".$zy_order['create_time']."'";
 }
 }else{
  $sql3="select * from zy_address where user_id ='".$zy_order['ord_id']."'";
}
    // echo $sql3;
	  $result3 = mysql_query($sql3);
	   while($zy_address=mysql_fetch_array($result3)){
	?>
	<tr>
	<td width="58" height="25"><a href="javascript:void(0);"  onclick="openwin('<?php echo $zy_order['ord_id'];?>')"><?php echo $zy_order['ord_id']; ?></a></td>
	  <td width="58" height="25"><?php  $sql2="select * from zy_shop where shop_id ='".$zy_order['shop_id']."'";
	  $result2 = mysql_query($sql2);
	   while($zy_shop=mysql_fetch_array($result2)){ echo $zy_shop['shop_name']; }?></td>
      <td width="58" height="25"><?php echo $zy_order['create_user']; ?></td>
      <td width="58" height="25"><?php echo $zy_address['address'];?></td>
	  <td width="58" height="25"><?php echo $zy_address['phone'];?></td>
	   <td width="58" height="25"><?php echo $zy_address['tel'];?></td>
      <td width="58" height="25"><?php echo $zy_order['remark'];?></td>
      <td width="58" height="25"><?php echo $zy_order['order_time'];?></td>
	  <td width="99" height="25"><?php echo number_format($zy_order['totalPrice']+20,2);?></td> 
	  </tr>
   <?php } ?> 
  <?php } ?>
    </table>
  <center>
 <?php
	//输出分页信息显示上一页和下一页
	echo "<br/><br/>";
	if($page!=1){
		echo "<a href='admin_search.php?page=1'>首页</a> ";
		echo "<a href='admin_search.php?page=".($page-1)."'>上一页</a> ";
	}
	for($i=$init;$i<=$max;$i++){?>
		<a href="admin_search.php?page=<?php echo $i;?>;" <?php echo $i==$page ? "class='current'":''?> ><?php echo $i;?></a>
	<?php 
	}
	if($page!=$maxPages){
		echo "<a href='admin_search.php?page=".($page+1)."'>下一页</a> ";
 		echo "<a href='admin_search.php?page={$maxPages}'>末页</a> ";
		
	}
?>
</center>
<script type="text/javascript">
function openwin(order_id){	
	if(navigator.appName=="Microsoft Internet Explorer"){	
		window.showModalDialog('item_show.php?id='+order_id,'','dialogWidth=900px;dialogHeight=600px');	
	}
	else if(navigator.appName=="Netscape"){		
		window.open('item_show.php?id='+order_id,'','width=900,height=600,modal=yes,location=no,status=no,toolbar=no,resizble=yes'); 
	}	
}

</script>
<h3 align="center"><a href="admin_management.php">返回</a></h3>
</form>
</body>
</html>